<template>
  <div class="app-container">
    <el-button @click="authorization">点击授权</el-button>
    <el-button @click="AppletInfo">点击查看小程序基本信息</el-button>
    <el-button @click="AuthorizerInfo">点击查看授权方信息</el-button>
    <el-button @click="registerApplet">创建小程序</el-button>
    <el-button @click="CreateTask">查询创建任务状态</el-button>
    <el-button @click="registerauth">复用公众号主体注册小程序</el-button><br>
    <!--    <el-button @click="intieAdmin"> 换绑小程序管理员接口</el-button>-->
    <el-button @click="setAppletNameClick">设置名字</el-button>
    <el-button @click="modifyheadimageClick">修改头像</el-button>
    <el-button @click="modifysignatureRequestClick">修改简介</el-button>
    <el-button @click="saveTemporaryMaterialClick">新增临时素材</el-button>
    <el-button @click="getTemporaryMaterialClick">获取临时素材</el-button>
    <el-button @click="appletLoginclick">小程序登录</el-button>
    <el-input v-model="code" placeholder="请输入左上角x坐标"/>

    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-row>
          <el-col :span="8" >
            <el-form-item label="企业名" prop="name">
              <el-input v-model="form.name" placeholder="请输入企业名"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="企业代码" prop="code">
              <el-input v-model="form.code"  placeholder="请输入企业代码"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" >
            <el-form-item label="企业代码类型" prop="name">
              <el-input v-model="form.codeType" placeholder="请输入企业代码类型"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="法人微信" prop="legalPersonaWechat">
              <el-input v-model="form.legalPersonaWechat"  placeholder="请输入法人微信"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" >
            <el-form-item label="法人姓名" prop="name">
              <el-input v-model="form.legalPersonaName" placeholder="请输入法人姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="第三方联系电话" prop="componentPhone">
              <el-input v-model="form.componentPhone"  placeholder="请输入第三方联系电话"/>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="unbindtitle" :visible.sync="unbindopen" width="900px" append-to-body>
      <el-form ref="unbinform" :model="unbinform"  label-width="80px">
        <el-row>
          <el-col :span="8" >
            <el-form-item label="昵称" prop="nickName ">
              <el-input v-model="unbinform.nickName" placeholder="请输入昵称"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="身份证照片mediaid" prop="idCard">
              <el-input v-model="unbinform.idCard" placeholder="请输入身份证照片mediaid"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="组织号" prop="license">
              <el-input v-model="unbinform.license" placeholder="请输入组织号mediaid"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="unbindsubmitForm">确 定</el-button>
        <el-button @click="unbindcancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="imgtitle" :visible.sync="imgopen" width="900px" append-to-body>
      <el-form ref="imgform" :model="imgform"  label-width="80px">
        <el-row>
          <el-col :span="8" >
            <el-form-item label="头像MediaId" prop="headImgMediaId ">
              <ImageUpload :imageStr="imgform.imageStr" :imageurl="imgform.imageurl"></ImageUpload>
<!--              <el-input v-model="imgform.headImgMediaId" placeholder="请输入头像MediaId"/>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8" >
            <el-form-item label="左上角x坐标" prop="x1">
              <el-input v-model="imgform.x1" placeholder="请输入左上角x坐标"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="左上角y坐标" prop="y1">
              <el-input v-model="imgform.y1" placeholder="请输入左上角y坐标"/>
            </el-form-item>
          </el-col>

          <el-col :span="8" >
            <el-form-item label="右下角x坐标" prop="x2">
              <el-input v-model="imgform.x2" placeholder="请输入右下角x坐标"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item label="右下角y坐标" prop="y2">
              <el-input v-model="imgform.y2" placeholder="请输入右下角y坐标"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="imgsubmitForm">确 定</el-button>
        <el-button @click="imgcancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog :title="title2" :visible.sync="open2" width="900px" append-to-body>
      <el-form ref="form2" :model="form2"  label-width="80px">
        <el-row>
          <el-col :span="8" >
            <el-form-item label="简介" prop="signature">
              <el-input v-model="form2.signature" placeholder="请输入简介"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title3" :visible.sync="open3" width="900px" append-to-body>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm3">确 定</el-button>
        <el-button @click="cancel3">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title4" :visible.sync="open4" width="900px" append-to-body>
      <el-form ref="form4" :model="form4"  label-width="80px">
        <el-row>
          <el-col :span="8" >
            <el-form-item label="mediaId" prop="mediaId">
              <el-input v-model="form4.mediaId" placeholder="请输入mediaId"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm4">确 定</el-button>
        <el-button @click="cancel4">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {appletGrant,
  getAppletInfo,
  getAuthorizerInfo,
  registerApplet,
  FindCreateTask,
  Fastregisterauth,
  IntieAdmin,
  setAppletNameRequest,
  modifyheadimageRequest,
  modifysignatureRequest,
  saveTemporaryMaterialRequest,
  getTemporaryMaterialRequest,
  appletLoginRequest,
  getPlatFromId} from "@/api/applet/authorization";
import ImageUpload from '@/components/ImageUpload/wechatUpload';
import { getToken } from "@/utils/auth";

export default {
  name: "Info",
  components: {
    ImageUpload
  },
  data() {
    return {
      uploadFileUrl: "http://localhost:9208/applet/saveTemporaryMaterial?platformid=" + 1, // 上传的图片服务器地址
      headers: {
        platformid: 1,
      },
      code:"",
      platformids:'',
      fileList: [],
      unbindtitle:"",
      unbindopen:false,
      imgtitle:"",
      imgopen:false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      title2: "",
      // 是否显示弹出层
      open2: false,
      title3: "",
      // 是否显示弹出层
      open3: false,
      title4: "",
      // 是否显示弹出层
      open4: false,
      // 表单参数
      form: {},
      form2: {},
      form3: {},
      form4: {},
      unbinform:{},
      imgform:{}
    };
  },
  created() {

  },
  methods: {
    // 上传成功回调
    handleUploadSuccess(res, file) {
      this.$message.success("上传成功");
      console.log(res)
      console.log(file)
      // saveTemporaryMaterialRequest().then(response => {
      //   console.log("新增临时素材成功"+response)
      // })
      // this.$emit("input", res.data.url);
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handleBeforeUpload(file){
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    //小程序登录
    appletLoginclick(){



      let code =  this.code;
      // let code = "013XKyml2u6Hl74to2ll2o54Wp2XKymv";
      appletLoginRequest(code).then(response => {
        console.log("小程序登录返回值:"+response)
      })
    },
    //点击授权
    authorization(){
      appletGrant().then(response => {
        let url = response.data.grantUrl;
        window.location.href = url;
      })
    },
    //点击授权
    AppletInfo(){
      getAppletInfo().then(response => {
        console.log("成功获取到基本信息"+response)
      })
    },
    AuthorizerInfo(){
      getAuthorizerInfo().then(response => {
        console.log("成功获取到授权方信息"+response)
      })
    },
    registerApplet(){
      this.open = true;
      this.title = "创建小程序";
    },
    CreateTask(){
      this.open = true;
      this.title = "查询创建任务状态";
    },
    registerauth(){
      Fastregisterauth().then(response => {
        console.log(response);
        let url = response.data.AuthorizationUrl;
        window.location.href = url;
      })
    },
    intieAdmin(){
      IntieAdmin().then(response => {
        console.log(response);
        let url = response.data.IntieUrl;
        window.location.href = url;
      })
    },
    setAppletNameClick(){
      this.unbindopen = true;
    },
    modifyheadimageClick(){
      this.imgopen = true;
    },
    modifysignatureRequestClick(){
      this.open2 = true;
    },
    saveTemporaryMaterialClick(){
      // getPlatFromId().then(response => {
      //   this.platformids = response;
      //   console.log(this.platformids)
      // })
      this.open3 = true;
    },
    getTemporaryMaterialClick(){
      this.open4 = true;
    },

    /** 提交按钮 */
    submitForm() {
      let code =  this.form.code;
      console.log(this.form);
      console.log(code);
      this.$refs["form"].validate(valid => {
        FindCreateTask(this.form).then(response => {
          console.log("创建任务状态"+response)
        })
        // if (code!=null){
        //   registerApplet(this.form).then(response => {
        //     this.msgSuccess("创建成功");
        //     this.open = false;
        //     console.log(response);
        //   });
        // }else {
        //
        // }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 提交按钮 */
    submitForm2() {
      this.$refs["form2"].validate(valid => {
        modifysignatureRequest(this.form2).then(response => {
          console.log("修改简介成功"+response)
        })
      });
    },
    // 取消按钮
    cancel2() {
      this.open2 = false;
    },

    /** 提交按钮 */
    submitForm3() {

      //C:\Users\Administrator\Desktop\u=3258583990,2139424876&fm=26&gp=0.jpg
      this.$refs["form3"].validate(valid => {
        saveTemporaryMaterialRequest(this.form3).then(response => {
          console.log("新增临时素材成功"+response)
        })
      });
    },
    // 取消按钮
    cancel3() {
      this.open3 = false;
    },

    /** 提交按钮 */
    submitForm4() {
      this.$refs["form4"].validate(valid => {
        getTemporaryMaterialRequest(this.form4).then(response => {
          console.log("获取临时素材成功"+response)
        })
      });
    },
    // 取消按钮
    cancel4() {
      this.open4 = false;
    },

    /** 提交按钮 */
    unbindsubmitForm() {
      this.$refs["unbinform"].validate(valid => {
        console.log(this.unbinform)
        setAppletNameRequest(this.unbinform).then(response => {
          console.log("设置名称成功"+response)
        })
      });
    },
    // 取消按钮
    unbindcancel() {
      this.unbindopen = false;
    },
    /** 提交按钮 */
    imgsubmitForm() {
      this.$refs["imgform"].validate(valid => {
        console.log(this.imgform)
        modifyheadimageRequest(this.imgform).then(response => {
          console.log("修改头像成功"+response)
        })
      });
    },
    // 取消按钮
    imgcancel() {
      this.imgopen = false;
    }
  }




};
</script>
